import Vue from 'vue'
// let c;
let Config = {
  root: "test-hot",
  temp: {
    noSave: [],//下次要提交的数据(未发送)
    dataTobe: [],//正在提交的数据(服务端正在处理),
    Vuebus: new Vue(),
    vroot: window._PAGE_FORX,
    ignore: true,
    tabel: null,
  },
  hotSettings: {
    startRows: 26, //行列范围
    startCols: 26,
    minRows: 26, //最小行列
    minCols: 26,
    rowHeaders: true, //行表头
    colHeaders: true,
    minSpareCols: 10, //列留白
    minSpareRows: 10, //行留白
    currentRowClassName: "currentRow", //为选中行添加类名，可以更改样式
    currentColClassName: "currentCol", //为选中列添加类名
    autoWrapRow: true, //自动换行
    contextMenu: {
      //自定义右键菜单，可汉化，默认布尔值
      items: {
        row_above: {
          name: "上方插入一行"
        },
        row_below: {
          name: "下方插入一行"
        },
        col_left: {
          name: "左方插入列"
        },
        col_right: {
          name: "右方插入列"
        },
        hsep1: "---------", //提供分隔线
        remove_row: {
          name: "删除行"
        },
        remove_col: {
          name: "删除列"
        },
        // make_read_only: {
        //   name: "只读"
        // },
        // alignment: {
        //   name: "对齐方式"
        // },
        // merge_cells: {
        //   name: "表格线"
        // },
        hsep2: "---------",
        undo: {
          name: '撤销'
        }, redo: {
          name: '重做'
        },
        hsep3: "---------",
        // MERGE_CELLS:{
        //   name:'合并'
        // },
        // merge_cells: {
        //   name: '合并1'
        // },
        commentsAddEdit: {
          name: "添加备注"
        },
        commentsRemove: {
          name: "取消备注"
        },
        // freeze_column: {
        //   name: "固定列"
        // },
        // unfreeze_column: {
        //   name: "取消列固定"
        // },
      }
    }, //右键效果
    fillHandle: true, //选中拖拽复制 possible values: true, false, "horizontal", "vertical"
    // fixedColumnsLeft: 0, //固定左边列数
    // fixedRowsTop: 0, //固定上边列数
    mergeCells: [
      //合并
      // { row: 1, col: 1, rowspan: 3, colspan: 3 }, //指定合并，从（1,1）开始行3列3合并成一格
      // { row: 3, col: 4, rowspan: 2, colspan: 2 }
    ],
    // columns: [
    //   //添加每一列的数据类型和一些配置
    //   {
    //     type: "date", //时间格式
    //     dateFormat: "YYYYMMDD",
    //     correctFormat: true,
    //     defaultDate: "19000101"
    //   },
    //   {
    //     type: "dropdown", //下拉选择
    //     source: ["BMW", "Chrysler", "Nissan", "Suzuki", "Toyota", "Volvo"],
    //     strict: false //是否严格匹配
    //   },
    //   { type: "numeric" }, //数值
    //   {
    //     type: "numeric",
    //     readOnly: true //设置只读
    //   },
    //   {
    //     type: "numeric",
    //     format: "$ 0,0.00"
    //   }, //指定的数据格式
    //   { type: "checkbox" } //多选框
    // ],
    // manualColumnFreeze: true, //手动固定列
    // manualColumnMove: true, //手动移动列
    // manualRowMove: true, //手动移动行
    manualColumnResize: true, //手工更改列距
    manualRowResize: true, //手动更改行距
    comments: true, //添加注释
    // cell: [{ row: 1, col: 1, comment: { value: "this is test" } }],
    afterRender: function () {
      Config.temp.table = this;
    },
    // customBorders: [], //添加边框
    // columnSorting: true, //排序
    // stretchH: "all", //根据宽度横向扩展，last:只扩展最后一列，none：默认不扩展,
    afterChange: function (data, name, z) {
      let no = Config.temp.noSave,
        bus = Config.temp.Vuebus,
        tobe = Config.temp.dataTobe,
        // root = Config.temp.vroot,
        tabel = Config.temp.tabel,
        isChange = false;
      for (let i in data) {
        data[i][0] = '' + data[i][0];
        data[i][1] = '' + data[i][1]
        let isChangeItem = !((data[i][2] == data[i][3]) || (data[i][2] == null && data[i][3] == ""))
        if (isChangeItem) {
          isChange = true
          no.push(data[i])
        }
      }
      if (isChange) {
        if (!Config.temp.ignore) {
          tobe.push(...no)
          no.splice(0, no.length)
          Vue.http({
            url: 'excel_addExcelContent',
            params: {
              contentList: JSON.stringify(Config.temp.dataTobe),
              'excel.eid': 1,
            },
          }).then((data) => {
            tobe.splice(0, tobe.length)
          }).catch(() => {
            no.push(...tobe)
            bus.$Message.error("提交失败,已保存在本地,下次保存再次提交");
            tobe.splice(0, tobe.length);
          })
          // console.log(this.getData());
        }
        else {
          no.splice(0, no.length);
          Config.temp.ignore = !Config.temp.ignore
        }
      }

      // console.log(no);
      // switch (name) {
      //   case "edit":
      //     // if (data[0][2] != data[0][3]) {
      //     console.log("编辑")
      //     //   no.push(data[0]);
      //     //   console.log(no);
      //     // }
      //     break;
      //   case "loadData":
      //     console.log("加载");
      //     break;
      //   case "Autofill.fill":
      //     console.log("格式刷");
      //     break;
      //   case "CopyPaste.paste":
      //     console.log("粘贴");
      //     break;
      //   case "UndoRedo.undo":
      //     console.log("撤销");
      //     break;
      //   case "UndoRedo.redo":
      //     console.log("重做");
      //     break;
      //   default:
      //     console.log("其他");
      //     console.log(name);
      //     console.log(data);
      //     break;
      // }
    },
    // 删除列
    afterRemoveCol: function (z, num, type) {
      Vue.http({
        url: 'excel_addCL',
        params: {
          'excelContent.excelLine ': z
        }
      })
      console.log('删除列');
      console.log(arguments);
    },
    afterRemoveRow: function (z, num, type) {
      console.log('删除行');
      console.log(arguments);
    },
    // 添加列
    afterCreateCol: function (z, num, type) {
      Vue.http({
        url: 'excel_addCLColumn',
        params: {
          'excelContent.excelColumn': z
        }
      })
    },
    // 添加行
    afterCreateRow: function (z, num, type) {
      Vue.http({
        url: 'excel_addCLLine',
        params: {
          'excelContent.excelLine': z
        }
      })
    }
  }
}
export default Config;